//
//  MPlusBaseViewController.m
//  medicineplus
//
//  Created by gufei on 15-4-14.
//  Copyright (c) 2015年 chn_ruby@126.cn. All rights reserved.
//

#import "MPlusBaseViewController.h"
#import "MPlusNavigationController.h"
#import "MPlusString.h"
#import "MPlusDefine.h"

@interface MPlusBaseViewController()<MBProgressHUDDelegate> {
    
}

@end

@implementation MPlusBaseViewController

#pragma mark -
#pragma mark UI Lazy Load Logic
- (UIView *)aInitContentView {
    return nil;
}

- (id)initWithNibName:(NSString *) nibNameOrNil bundle:(NSBundle *) nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self.view setBackgroundColor:[UIColor whiteColor]];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)setNavigationTitle:(NSString *) title {
    UILabel *_tilteLabel = [[UILabel alloc] init];
    [_tilteLabel setText:title];
    [_tilteLabel setBackgroundColor:[UIColor clearColor]];
    [_tilteLabel setTextColor:[UIColor blackColor]];
    //设置字体大小适应label宽度
    [_tilteLabel setAdjustsFontSizeToFitWidth:YES];
    [_tilteLabel setFont:[UIFont boldSystemFontOfSize:[kFontSize18 intValue]]];
    [_tilteLabel sizeToFit];
    [self.navigationItem setTitleView:_tilteLabel];
}

- (void)setNavigationTitleView:(NSString *) title setCGRect:(CGRect) rectMake {
    UIView *_uiView = [[UIView alloc]initWithFrame:CGRectMake(145, 7, 30, 30)];
    UIImageView *titleImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:title]];
    [_uiView addSubview:titleImageView];
    [self.navigationItem setTitleView:_uiView];
}

- (void)setNavigationLeft:(NSString *) title {
    
}

- (void)setNavigationRight:(NSString *) title {
    
}

/**
 * 基类：实现tabbar的资源设置
 */
- (void)setTabBarResource:(NSString *) title setImage:(NSString *) image setSelectedImage:(NSString *) selectedImage
{
    [self.tabBarItem setTitle:title];
    [self.tabBarItem setImage:[UIImage imageNamed:image]];
    [self.tabBarItem setSelectedImage:[UIImage imageNamed:selectedImage]];
}

// 显示正在加载视图
- (void)showLoadingView {
    loadingView.hidden = NO;
    [self.view addSubview:loadingView];
    [self.view bringSubviewToFront:loadingView];
}

- (void)showLoadingView:(NSString *) message {

}

// 显示加载失败视图
- (void)showLoadFailView {

}

- (void)showLoadFailView:(NSString *) message {

}

// 显示空视图
- (void)showEmptyView {

}

- (void)showEmptyView:(NSString *) message {

}

- (void)showEmptyView:(NSString *) message emptyIcon:(NSString *) icon {

}

// 重新加载视图
- (void)onReloadContent {

}

// 显示内容视图
- (void)showContentView {
    contentView = [self aInitContentView];
    if (nil != loadingView) {
        [loadingView removeFromSuperview];
    }
}

#pragma mark -
#pragma mark Show Toast
- (void)showToast:(NSString *) message {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = message;
    hud.margin = 15.f; // 文字距四周间距
    hud.yOffset = 0;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.0f];
}

#pragma mark -
#pragma mark Show Loading Dialog
- (void)showLoadingDialog {
    [self showLoadingDialog:kProcessing];
}

- (void)showLoadingDialog:(NSString *) msg {
    if (nil == HUD) {
        HUD = [[MBProgressHUD alloc] initWithView:self.view];
    }
    [self.view addSubview:HUD];
    // Set the hud to display with a color
    // HUD.color = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
    HUD.labelText = msg;
    HUD.labelFont = [UIFont systemFontOfSize:[kFontSize14 floatValue]];
    HUD.delegate = self;
    [HUD show:YES];
}

- (void)hideLoadingDialog {
    if (nil != HUD) {
        [HUD removeFromSuperview];
        HUD = nil;
    }
}

#pragma mark -
#pragma mark Show Alert Dialog
- (void)showAlertDialog:(NSString *) message {
    [self showAlertDialog:message confirm:kConfirm cancel:kCancel];
}

- (void)showAlertDialog:(NSString *) message confirm:(NSString *) confirm cancel:(NSString *) cancel {
    [self showAlertDialog:nil message:message confirm:confirm cancel:cancel];
}

- (void)showAlertDialog:(NSString *) title message:(NSString *) msg confirm:(NSString *) confirm cancel:(NSString *) cancel {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:cancel otherButtonTitles:confirm, nil];
    [alert show];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
